package pl.nazaweb.imedproplus.model.facade;

import java.util.List;
import javax.ejb.LocalBean;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import pl.nazaweb.imedproplus.model.entity.Icd9;

@LocalBean
@Stateless
public class Icd9Facade extends AbstractFacade<Icd9> {

    @PersistenceContext(unitName = AbstractFacade.peristanceUnitName)
    private EntityManager entityManager;

    public Icd9Facade() {
        super(Icd9.class);
    }

    @Override
    protected EntityManager getEntityManager() {
        return this.entityManager;
    }

    public List<String> getIcd9CodeList() {
        return this.getEntityManager().createNamedQuery("Icd9.findAllCode").getResultList();
    }

    @Override
    public void edit(Icd9 entity) {
        this.getEntityManager()
                .createNativeQuery("update icd9 set code=:code, name=:name, status=:status where code=:code")
                .setParameter("code", entity.getCode())
                .setParameter("name", entity.getName())
                .setParameter("status", entity.getStatus())
                .executeUpdate();
    }
    
}
